CMAKE_MINIMUM_REQUIRED(VERSION 3.0...3.20)
PROJECT(gear-lib)

INCLUDE_DIRECTORIES(.)

LIST(APPEND SOURCE_FILES libposix.c)

IF (DEFINED OS_LINUX OR DEFINED ENV_MINGW)
LIST(APPEND SOURCE_FILES libposix4nix.c)
ELSEIF (DEFINED OS_WINDOWS)

IF (DEFINED ENV_MINGW)
add_compile_definitions(ENV_MINGW=true)
ELSE ()
INCLUDE_DIRECTORIES(pthreads4w/ MsvcLibX/include)
AUX_SOURCE_DIRECTORY(MsvcLibX MSVCLIBX_SRC)
LIST(APPEND PTHREADS4W_SRC pthreads4w/pthread.c)
LIST(APPEND SOURCE_FILES ${MSVCLIBX_SRC} ${PTHREADS4W_SRC})
set(CMAKE_C_FLAGS_DEBUG "/DUCRTINCLUDE=$(VCInstallDir)include ${CMAKE_C_FLAGS_DEBUG}")
set(CMAKE_C_FLAGS_DEBUG "/DMSVCINCLUDE=$(VCInstallDir)include ${CMAKE_C_FLAGS_DEBUG}")
set(CMAKE_C_FLAGS_DEBUG "/DWSDKINCLUDE=$(WindowsSdkDir)Include ${CMAKE_C_FLAGS_DEBUG}")
LIST(APPEND SOURCE_FILES libposix4win.c)
ENDIF ()

ENDIF ()

ADD_LIBRARY(posix ${SOURCE_FILES})
